<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">

    <xsl:template name="itemizedlist.label.markup">
        <xsl:param name="itemsymbol">square</xsl:param>
        <xsl:choose>
            <xsl:when test="$itemsymbol='none'"/>
            <xsl:when test="$itemsymbol='disc'">&#x2022;</xsl:when>
            <xsl:when test="$itemsymbol='bullet'">&#x2022;</xsl:when>
            <xsl:when test="$itemsymbol='endash'">&#x2013;</xsl:when>
            <xsl:when test="$itemsymbol='emdash'">&#x2014;</xsl:when>
            <xsl:when test="$itemsymbol='square'">
                <xsl:choose>
                    <xsl:when test="$use.svg.itemsymbols">
                        <xsl:call-template name="gen-svg-square">
                            <xsl:with-param name="size">6pt</xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>&#x25A0;</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$itemsymbol='box'">&#x25A0;</xsl:when>
            <xsl:when test="$itemsymbol='smallblacksquare'">
                <xsl:choose>
                    <xsl:when test="$use.svg.itemsymbols">
                        <xsl:call-template name="gen-svg-square">
                            <xsl:with-param name="size">4pt</xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>&#x25AA;</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$itemsymbol='circle'">&#x25CB;</xsl:when>
            <xsl:when test="$itemsymbol='opencircle'">&#x25CB;</xsl:when>
            <xsl:when test="$itemsymbol='whitesquare'">&#x25A1;</xsl:when>
            <xsl:when test="$itemsymbol='smallwhitesquare'">&#x25AB;</xsl:when>
            <xsl:when test="$itemsymbol='round'">&#x25CF;</xsl:when>
            <xsl:when test="$itemsymbol='blackcircle'">&#x25CF;</xsl:when>
            <xsl:when test="$itemsymbol='whitebullet'">&#x25E6;</xsl:when>
            <xsl:when test="$itemsymbol='triangle'">&#x2023;</xsl:when>
            <xsl:when test="$itemsymbol='point'">&#x203A;</xsl:when>
            <xsl:when test="$itemsymbol='hand'">
                <fo:inline font-family="Wingdings 2">A</fo:inline>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>&#x2022;</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="next.itemsymbol">
        <xsl:param name="itemsymbol">square</xsl:param>
        <xsl:choose>
            <xsl:when test="$itemsymbol = 'disc'">circle</xsl:when>
            <xsl:when test="$itemsymbol = 'circle'">square</xsl:when>
            <xsl:when test="$itemsymbol = 'square'">smallblacksquare</xsl:when>
            <xsl:when test="$itemsymbol = 'smallblacksquare'">smallblacksquare</xsl:when>
            <xsl:otherwise>square</xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="procedure/step|substeps/step">
        <xsl:variable name="id">
            <xsl:call-template name="object.id"/>
        </xsl:variable>
        <fo:list-item xsl:use-attribute-sets="list.item.spacing">
            <fo:list-item-label end-indent="label-end()">
                <fo:block id="{$id}" xsl:use-attribute-sets="step.label.properties">
                    <xsl:choose>
                        <xsl:when test="count(../step) = 1">
                            <xsl:call-template name="itemizedlist.label.markup"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="." mode="number">
                                <xsl:with-param name="recursive" select="0"/>
                            </xsl:apply-templates>. </xsl:otherwise>
                    </xsl:choose>
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>

    <xsl:template match="simplelist[not(@type)]|simplelist[@type='vert']">
        <!-- with no type specified, the default is 'vert' -->
        <xsl:element name="fo:table" use-attribute-sets="list.block.spacing">
            <xsl:call-template name="simplelist.table.columns">
                <xsl:with-param name="cols">
                    <xsl:choose>
                        <xsl:when test="@columns">
                            <xsl:value-of select="@columns"/>
                        </xsl:when>
                        <xsl:otherwise>1</xsl:otherwise>
                    </xsl:choose>
                </xsl:with-param>
            </xsl:call-template>
            <xsl:element name="fo:table-body">
                <xsl:attribute name="start-indent">0pt</xsl:attribute>
                <xsl:attribute name="end-indent">0pt</xsl:attribute>
                <xsl:call-template name="simplelist.vert">
                    <xsl:with-param name="cols">
                        <xsl:choose>
                            <xsl:when test="@columns">
                                <xsl:value-of select="@columns"/>
                            </xsl:when>
                            <xsl:otherwise>1</xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="simplelist[@type='inline']">
        <!-- if dbchoice PI exists, use that to determine the choice separator -->
        <!-- (that is, equivalent of "and" or "or" in current locale), or literal -->
        <!-- value of "choice" otherwise -->
        <fo:inline>
            <xsl:variable name="localized-choice-separator">
                <xsl:choose>
                    <xsl:when test="processing-instruction('dbchoice')">
                        <xsl:call-template name="select.choice.separator"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <!-- empty -->
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>

            <xsl:for-each select="member">
                <xsl:apply-templates/>
                <xsl:choose>
                    <xsl:when test="position() = last()"/>
                    <!-- do nothing -->
                    <xsl:otherwise>
                        <xsl:text>, </xsl:text>
                        <xsl:if test="position() = last() - 1">
                            <xsl:if test="$localized-choice-separator != ''">
                                <xsl:value-of select="$localized-choice-separator"/>
                                <xsl:text> </xsl:text>
                            </xsl:if>
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
        </fo:inline>
    </xsl:template>

    <xsl:template match="simplelist[@type='horiz']">

        <xsl:variable name="explicit.table.width">
            <xsl:call-template name="dbfo-attribute">
                <xsl:with-param name="pis" select="processing-instruction('dbfo')"/>
                <xsl:with-param name="attribute" select="'list-width'"/>
            </xsl:call-template>
        </xsl:variable>

        <xsl:variable name="table.width">
            <xsl:choose>
                <xsl:when test="$explicit.table.width != ''">
                    <xsl:value-of select="$explicit.table.width"/>
                </xsl:when>
                <xsl:when test="$default.table.width = ''">
                    <xsl:text>100%</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$default.table.width"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <fo:table xsl:use-attribute-sets="normal.para.spacing">
            <xsl:choose>
                <xsl:when test="$axf.extensions != 0 or $xep.extensions != 0">
                    <xsl:attribute name="table-layout">auto</xsl:attribute>
                    <xsl:if test="$explicit.table.width != ''">
                        <xsl:attribute name="width">
                            <xsl:value-of select="$explicit.table.width"/>
                        </xsl:attribute>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="table-layout">fixed</xsl:attribute>
                    <xsl:attribute name="width">
                        <xsl:value-of select="$table.width"/>
                    </xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:call-template name="simplelist.table.columns">
                <xsl:with-param name="cols">
                    <xsl:choose>
                        <xsl:when test="@columns">
                            <xsl:value-of select="@columns"/>
                        </xsl:when>
                        <xsl:otherwise>1</xsl:otherwise>
                    </xsl:choose>
                </xsl:with-param>
            </xsl:call-template>
            <fo:table-body start-indent="0pt" end-indent="0pt">
                <xsl:call-template name="simplelist.horiz">
                    <xsl:with-param name="cols">
                        <xsl:choose>
                            <xsl:when test="@columns">
                                <xsl:value-of select="@columns"/>
                            </xsl:when>
                            <xsl:otherwise>1</xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>
            </fo:table-body>
        </fo:table>
    </xsl:template>

    <xsl:template match="stepalternatives/step">
        <xsl:variable name="id">
            <xsl:call-template name="object.id"/>
        </xsl:variable>

        <fo:list-item xsl:use-attribute-sets="list.item.spacing">
            <fo:list-item-label end-indent="label-end()">
                <fo:block id="{$id}" xsl:use-attribute-sets="step.label.properties">
                    <xsl:call-template name="itemizedlist.label.markup"/>
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>

    <xsl:template match="varlistentry/term">
        <!-- modified to use attributes-set term.properties -->
        <xsl:element name="fo:inline" use-attribute-sets="term.properties">
            <xsl:apply-templates/>
        </xsl:element>
        <xsl:choose>
            <xsl:when test="not(following-sibling::term)"/>
            <!-- do nothing -->
            <xsl:otherwise>
                <!-- * if we have multiple terms in the same varlistentry, generate -->
                <!-- * a separator (", " by default) and/or an additional line -->
                <!-- * break after each one except the last -->
                <fo:inline>
                    <xsl:value-of select="$variablelist.term.separator"/>
                </fo:inline>
                <xsl:if test="not($variablelist.term.break.after = '0')">
                    <fo:block/>
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
